
	/*--判斷特定欄位值是否有填--*/
	function isEmpty(str) { 
		for (var i = 0; i < str.length; i++)
			if (" " != str.charAt(i))return false; 
			return true; 
	}

	function Check(f) { 
		var Lens = 0, tmps = 0;
		var tmp;
		var oo = document.CheckDataForm;
		//Lens = parseInt(oo.requirednum.value);
		for (var i = 0; i < oo.required.length; i++){
			tmp = oo.required[i].value.split(";");
			if (null != f[tmp[1]]){
				if(tmp[0] == "text"){
					if(f[tmp[1]].type.indexOf("select") > -1){
						if (isEmpty(f[tmp[1]].options[f[tmp[1]].selectedIndex].value))return EmptyAlert("If you have some columns forgot to fill it! \n\n"+tmp[2],f[tmp[1]]);
						//alert(f[tmp[1]].options[f[tmp[1]].selectedIndex].value);
					}else{
						if (isEmpty(f[tmp[1]].value))return EmptyAlert("If you have some columns forgot to fill it! \n\n"+tmp[2],f[tmp[1]]);
					}
				}else if(tmp[0] == "int"){
					if (isEmpty(f[tmp[1]].value))return EmptyAlert("If you have some columns forgot to fill it! \n\n"+tmp[2],f[tmp[1]]);
					if (isNaN(f[tmp[1]].value))return EmptyAlert("Please fill the column with numerals!\n\n"+tmp[2],f[tmp[1]]);
				}else if(tmp[0] == "ints"){
					if (!isEmpty(f[tmp[1]].value))if(isNaN(f[tmp[1]].value))return EmptyAlert("Please fill the column with numerals!\n\n"+tmp[2],f[tmp[1]]);
				}else if(tmp[0] == "radio"){
					tmps = 0;
					for(var j = 0; j < f[tmp[1]].length; j++)if(f[tmp[1]][j].checked)tmps = 1;
					if(tmps == 0)return EmptyAlert("If you have some columns forgot to choose it! \n\n"+tmp[2],f[tmp[1]][0]);
				}else if(tmp[0] == "checkbox"){
					tmps = 0;
					for(var j = 0; j < f[tmp[1]].length; j++)if(f[tmp[1]][j].checked)tmps += 1;
					if(parseInt(tmp[3]) == parseInt(tmp[4]) && tmps != parseInt(tmp[3])){
						return EmptyAlert("at this column you only can choose " + tmp[3] + " items!\n\n"+tmp[2],f[tmp[1]][0]);
					}else if(parseInt(tmp[3]) > 0 && tmps < parseInt(tmp[3])){
						return EmptyAlert("at this column you should at least choose " + tmp[3] + " items!\n\n"+tmp[2],f[tmp[1]][0]);
					}else if(parseInt(tmp[4]) > 0 && tmps > parseInt(tmp[4])){
						return EmptyAlert("at this column you should choose not more than " + tmp[4] + " items!\n\n"+tmp[2],f[tmp[1]][0]);
					}
				}else if(tmp[0] == "Email"){
					if(f[tmp[1]] != null)if (!verifyAddress(f[tmp[1]]))return false;	
				}else if(tmp[0] == "Emails"){
					if(f[tmp[1]] != null && !isEmpty(f[tmp[1]].value))if (!verifyAddress(f[tmp[1]]))return false;	
				}
			}else if(tmp[0] == "Date"){
				intMonth = f[tmp[1]+"Mon"].options[f[tmp[1]+"Mon"].selectedIndex].value;
				intDay = f[tmp[1]+"Day"].options[f[tmp[1]+"Day"].selectedIndex].value;
				if (!checkDateFormat(f[tmp[1]+"Year"].value,intMonth,intDay))return EmptyAlert("If you have some columns forgot to choose it or date type is not correct!\n\n"+tmp[2],f[tmp[1]+"Year"]);
			}
		}
		return true;
	}

	function EmptyAlert(strTmp,objs){
		alert(strTmp);
		objs.focus();
		return false;				
	}

	/*--檢查密碼--*/
	function verifyPWD(obj) { 
		var email = obj.value;
		var pattern = /^([a-zA-Z0-9_-])+/;
		if (email.length > 15 || email.length < 6){
			alert("The password should be 6-15 chars"); 
			obj.focus();
			return false; 
		}
	    flag = pattern.test(email); 

		if(flag) { 
			return true; 
		}else { 
			alert("The password should be numberals or letters!\n Please don't use the special marks!"); 
			obj.focus();
			return false; 
		} 
	} 		

	/*--檢查電子郵件--*/
	function verifyAddress(obj) { 
		// obtain form value into variable 
		var email = obj.value; 
		 // define regex 
		var pattern = /^([a-zA-Z\.0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/; 
		// test for pattern 
		if (email.length = 0)return true;
	    flag = pattern.test(email); 

		if(flag) { 
			//alert("Email檢查無誤"); 
			return true; 
		}else { 
			alert("Not Correct Email"); 
			obj.focus();
			return false; 
		} 
	} 	

/*--檢驗日期--*/
function checkDateFormat(iYear, iMonth, iDay) {
	if (iDay == null || iMonth == null || iYear == null)  { return false; }
	if (iYear.length != 4 || isNaN(iYear) || iYear <= 0)  { return false; }
	if (iMonth.length == 0 || iMonth <= 0)  { return false; }
	if (iDay.length == 0 || iDay <= 0)  { return false; }

	if ((iMonth == 4) || 
		(iMonth == 6) || 
		(iMonth == 9) || 
		(iMonth == 11) ) {
		if (iDay > 30) { return false; }  
		}

	if (iMonth==2) {
		if ((iYear % 4)==0) {
			if (iDay > 29) { return false; }
		} else {
			if (iDay > 28) { return false; } 
		}
	}
	return true;
  }


	function CheckillegalPassword(PWDObj, cPWDObj){
		if(PWDObj.value.length < 6 && PWDObj.value.length >= 0){
			alert(" Password shall be at least 6 alphanumberic letters.");
			PWDObj.focus();
		}else if(PWDObj.value != cPWDObj.value){
			alert("Please make sure if  the capital or lowercase of the letters in new password field and new password confirm field are the same or not.");
			PWDObj.focus();
		}else if(illegalPassword(PWDObj.value)){
			alert(" Please use a-z, A-Z, 0-9, _, @. ");
			PWDObj.focus();
		}else if(illegalPassword2(PWDObj.value)){
			alert(" Each letter of the password should not be the same. ");
			PWDObj.focus();
		}else{
			return true;
		}
		return false;
	}

	function illegalPassword(idd){
		var xid =  idd.toUpperCase();
		if(idd.length == 0)  return  false;
		var c  =  xid.charAt(0);
		for(var i = 0; i < xid.length; i++) {
			c = xid.charAt(i);
			if(!((('0'<=c)&&(c<='9'))||(('A'<=c)&&(c<='Z')) || c=='@' || c<='_')) return true;
		}
		return  false;		
	}

	function illegalPassword2(idd){
		var xid =  idd.toUpperCase();
		var c  =  xid.charAt(0);
		for(var i = 1; i < xid.length; i++) {
			if(c != xid.charAt(i))return false;
		}
		return true;
	}